let input = `8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda`

let input_arr = input.split('\n')

let count = parseInt(input_arr[0])

let student_arr = []
for(let i=0; i<count; i++){
    let arr = input_arr[i+1].split(' ')
    let student_info = {
        sex:arr[0],
        stu_name:arr[1]
    }
    student_arr.push(student_info)
}
let girls = student_arr.filter((item)=>item.sex==='0')
let boys = student_arr.filter((item)=>item.sex==='1')
let pair_count = 0
for(let i=0; i<student_arr.length; i++){
    if(pair_count === student_arr.length / 2){
        break
    }
    let stu_info = student_arr[i]
    if(stu_info.sex==='0'){
        let boy = boys.pop()
        console.log(`${stu_info.stu_name} ${boy.stu_name}`);

    }
    else if(stu_info.sex==='1'){
        let girl = girls.pop()
        console.log(`${stu_info.stu_name} ${girl.stu_name}`);
}
pair_count++
}
